{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Populating the interactive namespace from numpy and matplotlib\n"
     ]
    }
   ],
   "source": [
    "from ipywidgets import interact, interactive, FloatSlider, IntSlider, ToggleButtons\n",
    "from geoscilabs.em.TDEMInductiveSource import choose_source, load_or_run_results, PlotTDEM\n",
    "%pylab inline"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Exploring fields from inductive sources"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Purpose\n",
    "\n",
    "We explore time-domain electromagnetic (EM) simulation results from inductive sources. Both electric currents and magnetic flux will be visualized to undertand physics of inductive source EM. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Load simulation results (or run)\n",
    "\n",
    "Two inductive sources are considered:\n",
    "\n",
    "- Vertical magnetic dipole(VMD)\n",
    "- Horizontal magnetic dipole(HMD)\n",
    "\n",
    "Using below widget, you can choose a model that you want to explore. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "32df6ce723af42a680ceb1469ae11475",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "interactive(children=(ToggleButtons(description='src_type', options=('VMD', 'HMD'), value='VMD'), Output()), _…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "Q = interact(choose_source, \n",
    "         src_type=ToggleButtons(\n",
    "             options=[\"VMD\", \"HMD\"], value=\"VMD\"\n",
    "         )\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Then here we are going to load results. If you want to rerun, you can set `re_run` as `True`. \n",
    "With that option, you can change conductivity value of the block and halfspace you can alter a value for `sigma_halfspace`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "file already exists, new file is called /Users/lindseyjh/git/geosci/geosci-labs/notebooks/em/tdem_inductivesource.tar\n",
      "Downloading https://storage.googleapis.com/simpeg/em_examples/tdem_inductivesource/tdem_inductivesource.tar\n",
      "   saved to: /Users/lindseyjh/git/geosci/geosci-labs/notebooks/em/tdem_inductivesource.tar\n",
      "Download completed!\n"
     ]
    }
   ],
   "source": [
    "import matplotlib\n",
    "matplotlib.rcParams['font.size']=16\n",
    "options = load_or_run_results(\n",
    "    re_run=False, \n",
    "    fname=choose_source(Q.widget.kwargs['src_type']),\n",
    "    src_type=Q.widget.kwargs['src_type'],\n",
    "    sigma_halfspace=0.01\n",
    ")\n",
    "tdem = PlotTDEM(**options)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "0e35680c59374b95a42141e55e5e3f85",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "interactive(children=(FloatSlider(value=30.0, description='elev', max=180.0, min=-180.0, step=10.0), FloatSlid…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "<function ipywidgets.widgets.interaction._InteractFactory.__call__.<locals>.<lambda>(*args, **kwargs)>"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "interact(\n",
    "    tdem.show_3d_survey_geometry, \n",
    "    elev=FloatSlider(min=-180, max=180, step=10, value=30),\n",
    "    azim=FloatSlider(min=-180, max=180, step=10, value=-45),\n",
    ")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "37f37f7e4dae407cb0a81d0f6d9a934a",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "interactive(children=(IntSlider(value=15, description='itime', max=50, min=15), ToggleButtons(description='sca…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "<function ipywidgets.widgets.interaction._InteractFactory.__call__.<locals>.<lambda>(*args, **kwargs)>"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "interact(\n",
    "    tdem.plot_input_currents, \n",
    "    itime=IntSlider(min=15, max=50, step=1, value=15, contiusous_update=False),\n",
    "    scale=ToggleButtons(\n",
    "        options=[\"linear\", \"log\"], value=\"linear\"\n",
    "    ),\n",
    "    \n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "d221b2c7133445e48714b68fe032df83",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "interactive(children=(IntSlider(value=10, description='itime', max=50, min=10, step=2), Output()), _dom_classe…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "<function ipywidgets.widgets.interaction._InteractFactory.__call__.<locals>.<lambda>(*args, **kwargs)>"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "interact(\n",
    "    tdem.plot_electric_currents, \n",
    "    itime=IntSlider(min=10, max=50, step=2, value=10, contiusous_update=False)\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "d19d488f0c184bdcafbc8030e0137f98",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "interactive(children=(IntSlider(value=10, description='itime', max=50, min=10, step=2), Output()), _dom_classe…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "<function ipywidgets.widgets.interaction._InteractFactory.__call__.<locals>.<lambda>(*args, **kwargs)>"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "interact(\n",
    "    tdem.plot_magnetic_flux, \n",
    "    itime=IntSlider(min=10, max=50, step=2, value=10, contiusous_update=False)\n",
    ")"
   ]
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
